<?php
// +----------------------------------------------------------------------
// | @filename CreateAdminUserRequest.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-29 13:51:33
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Requests\AdminUser;


use Addons\Backend\Http\Requests\BaseRequest;

class CreateAdminUserRequest extends BaseRequest
{
    public function rules(): array
    {
        return [
            'username' => ['bail', 'required', 'min:2', 'max:40', 'unique:admin_users,username'],
            'password' => ['bail', 'required', 'min:6', 'max:30'],
            'nickname' => ['bail', 'required', 'min:2', 'max:40', 'unique:admin_users,nickname'],
            'email' => ['bail', 'nullable', 'email'],
            'mobile' => ['bail', 'required', 'regex:/^1[3-9]\d{9}$/', 'unique:admin_users,mobile'],
            'status' => ['bail', 'required','in:1,2'],
            'gender'=>  ['bail', 'required','in:0,1,2'],
            'avatar'=>  ['bail', 'nullable'],
        ];
    }

    public function messages(): array
    {
        return [
            'username.required' => '请输入用户名',
            'username.unique' => '用户名已存在',
            'username.min' => '用户名不能少于2位',
            'username.max' => '用户名不能大于40位',
            'nickname.required' => '请输入昵称',
            'nickname.unique' => '昵称已存在',
            'nickname.min' => '昵称不能少于2位',
            'nickname.max' => '昵称不能大于40位',
            'password.required' => '请输入密码',
            'password.min' => '密码不能少于6位',
            'password.max' => '密码不能大于30位',
            'email.email' => '邮箱格式不正确',
            'mobile.required' => '请输入手机号',
            'mobile.regex' => '手机号格式不正确',
            'mobile.unique' => '手机号已存在',
            'status.required' => '请选择状态',
            'status.in' => '选择的状态不正确',
            'gender.required' => '请选择性别',
            'gender.in' => '选择的性别不正确'
        ];
    }

    public function authorize(): bool
    {
        return true;
    }
}
